﻿Imports Tohto.Base.CommonConst
Imports Tohto.Web.BLL
Imports Tohto.Base.Entity
Imports AjaxControlToolkit

Public Class UT0100P01
    Inherits CMDialogBasePage

#Region "定数"

    ''' <summary>
    ''' 画面ID
    ''' </summary>
    ''' <remarks></remarks>
    Private Const PAGE_ID As String = "UT0100P01"

    ''' <summary>
    ''' 画面名称
    ''' </summary>
    ''' <remarks></remarks>
    Private Const PAGE_NM As String = "工事参照"

#End Region

#Region "フォームイベント"

    ''' <summary>
    ''' フォームロード
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Try
            'エラーメッセージリストの初期化
            Call ErrMessageInit()

            If Not IsPostBack Then
                '画面の初期化
                Call PageInit()
            End If

        Catch ex As Exception
            MyBase.ProcessException(ex, ComConst.EX_HANLDER_UI, True)
        End Try

    End Sub

#End Region

#Region "ボタンクリックイベント"

    ''' <summary>
    ''' 検索ボタンを押下する場合、検索処理を行う
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Protected Sub btn_search_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_search.Click
        Try

            Dim UT0100P01 As New UT0100P01B01
            'ログインユーザーを取得
            Dim sessionUserInfo As SessionUserInfo = DirectCast(Session(ComConst.SEE_USER_INFO), SessionUserInfo)

            Dim retDt As DataTable = UT0100P01.Fetch_LIST(sessionUserInfo.EMPLOYEE_CD, _
                                                          Me.txt_koji_no.Text, _
                                                          Me.txt_koji_nm.Text, _
                                                          Me.kojikb_drop.SelectedValue, _
                                                          Me.kojist_drop.SelectedValue, _
                                                          Me.txt_article_cd.Text, _
                                                          Me.article_nm.Text, _
                                                          Me.dtfrom.Text, _
                                                          Me.dtto.Text, _
                                                          Me.tantopostcd.SelectedValue, _
                                                          Me.tantocd.Text, _
                                                          errInfo)


            If retDt.Rows.Count = 0 Then
                Call MyBase.SetMsgArea("CMI0003")
                Exit Sub
            Else

                'エラーメッセージ領域をクリア
                Call MyBase.ErrMsgAreaClear()

                '手配履歴画面の初期化
                Call SpreadInit(retDt)

                Me.spd_Bukken.Focus()
                Me.spd_Bukken.ActiveSheetView.ActiveRow = 0

            End If

        Catch ex As Exception
            MyBase.ProcessException(ex, ComConst.EX_HANLDER_UI)
        End Try
    End Sub

    ''' <summary>
    ''' クリアボタンを押下する場合、初期化処理を行う
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Protected Sub btn_clear_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_clear.Click
        Try

            ' 画面のクリア
            Call PageClear()

        Catch ex As Exception
            MyBase.ProcessException(ex, ComConst.EX_HANLDER_UI)
        End Try
    End Sub

#End Region

#Region "メソッド"

    ''' <summary>
    ''' 画面の初期化
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub PageInit()

        'スプレッドのStyle
        Call MyBase.SetSpreadDefaultStyle(Me.spd_Bukken, True)

        Call InitDropDownList(ComConst.CMB_BUSYO, tantopostcd)
        Call InitDropDownList(ComConst.CMB_KB, kojikb_drop, ComConst.KUBUN.KJ001)
        Call InitDropDownList(ComConst.CMB_KB, kojist_drop, ComConst.KUBUN.KJ002)
        
        '画面クリア
        Call PageClear()

    End Sub

    ''' <summary>
    ''' 画面クリア
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub PageClear()

        'エラーメッセージ領域のクリア
        Call MyBase.ErrMsgAreaClear()

        '工事No.
        Me.txt_koji_no.Text = String.Empty
        '工事名
        Me.txt_koji_nm.Text = String.Empty
        '工事区分
        Me.kojikb_drop.SelectedIndex = 0
        '工事案件状態
        Me.kojist_drop.SelectedIndex = 0
        '物件CD
        Me.txt_article_cd.Text = String.Empty
        '物件名(カナ)
        Me.article_nm.Text = String.Empty
        '工事案件完了日From
        Me.dtfrom.Text = MyBase.GetSystemDate.ToShortDateString
        '工事案件完了日To
        Me.dtto.Text = MyBase.GetSystemDate.ToShortDateString
        '工事担当部署
        Me.tantopostcd.SelectedIndex = 0
        '工事担当者CD
        Me.tantocd.Text = String.Empty
        '工事担当者NAME
        Me.tantonm.Text = String.Empty

        'spread clear
        Me.spd_Bukken.ActiveSheetView.RowCount = 0
        '部署CD FOCUS
        Me.txt_koji_no.Focus()

    End Sub

    ''' <summary>
    ''' エラーメッセージリストの初期化
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub ErrMessageInit()

        '行が選択されていない場合はエラー。
        arrErrorCdList.Add("CME0061")

        'データテーブルにデータが存在しなかった場合はエラーとする。
        arrErrorCdList.Add("CMI0003")

        '回収予定日(From)＞回収予定日(To)の場合はエラーとする。
        arrErrorCdList.Add("CME0033")

        'クライアントにポープメッセージ共通をレジスト
        MyBase.RegistErrorCdToForm()

        'クライアントにポープメッセージ共通をレジスト
        MyBase.RegistErrorCdToForm()

    End Sub

    ''' <summary>
    ''' 手配履歴画面の初期化
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub SpreadInit(ByVal dtTmp As DataTable)


        Me.spd_Bukken.Rows.Count = 0
        Me.spd_Bukken.Rows.Count = dtTmp.Rows.Count

        For i As Integer = 0 To dtTmp.Rows.Count - 1
            Me.spd_Bukken.Cells(i, 0).Value = dtTmp.Rows(i).Item("KOJI_NO")            '工事No.
            Me.spd_Bukken.Cells(i, 1).Value = dtTmp.Rows(i).Item("KOJI_NM")            '工事名
            Me.spd_Bukken.Cells(i, 2).Value = dtTmp.Rows(i).Item("KOJI_KB")            '工事区分
            Me.spd_Bukken.Cells(i, 3).Value = dtTmp.Rows(i).Item("KOJI_ST_NM")         '工事案件状態名
            Me.spd_Bukken.Cells(i, 4).Value = dtTmp.Rows(i).Item("ARTICLE_CD")         '物件CD
            Me.spd_Bukken.Cells(i, 5).Value = dtTmp.Rows(i).Item("ARTICLE_NM")         '物件名
            Me.spd_Bukken.Cells(i, 6).Value = dtTmp.Rows(i).Item("ROOM_CD")            '部屋CD
            Me.spd_Bukken.Cells(i, 7).Value = dtTmp.Rows(i).Item("ROOM_NM")            '部屋名
            Me.spd_Bukken.Cells(i, 8).Value = dtTmp.Rows(i).Item("OWNER_CUST_CD")      'オーナーCD
            Me.spd_Bukken.Cells(i, 9).Value = dtTmp.Rows(i).Item("OWNER_CUST_NM")      'オーナー名
            Me.spd_Bukken.Cells(i, 10).Value = dtTmp.Rows(i).Item("CONTRA_CUST_CD")    '契約者CD
            Me.spd_Bukken.Cells(i, 11).Value = dtTmp.Rows(i).Item("CONTRA_CUST_NM")    '契約者CD名
            Me.spd_Bukken.Cells(i, 12).Value = dtTmp.Rows(i).Item("TENANT_CUST_CD")    '入居者CD
            Me.spd_Bukken.Cells(i, 13).Value = dtTmp.Rows(i).Item("TENANT_CUST_NM")    '入居者名
        Next

        'spreadの行数指定
        Me.spd_Bukken.ActiveSheetView.PageSize = dtTmp.Rows.Count

    End Sub


    ''' <summary>
    ''' Spread Double Click
    ''' </summary>
    ''' <param name="writer"></param>
    ''' <remarks></remarks>
    Protected Overrides Sub Render(writer As System.Web.UI.HtmlTextWriter)
        Dim spTable As Table = DirectCast(Me.spd_Bukken.FindControl("viewport"), Table)
        spTable.Attributes.Add("ondblclick", "return BukkenCheck()")

        MyBase.Render(writer)
    End Sub

#End Region


End Class